/*
 * @Author: zhangwei 1405298045@qq.com
 * @Date: 2022-03-03 15:51:19
 * @LastEditTime: 2022-03-12 14:24:50
 * @LastEditors: zhangwei 1405298045@qq.com
 * @Description:
 * @FilePath: /ll-fe-mp-dyfx/src/store/modules/system.js
 *	actions => dispatch
 */

import srorageKey from '@/utils/srorage/key';
import { getLocal, setLocal } from '@/utils';

export default {
	state: {
		systemInfo: {},
		userInfo: getLocal(srorageKey.userInfo) || {},
		token: getLocal(srorageKey.AuthorizedToken) || '',
		dyCodeImage: '',
		userOperateId: 0,
		isShowNotBind: false,
		isShowNotBindCode: false
	},

	getters: {
		getToken({ token }) {
			return token;
		},

		getSystemInfo({ systemInfo }) {
			return systemInfo;
		},

		userInfo({ userInfo }) {
			return userInfo;
		},

		getDyCodeImage({ dyCodeImage }) {
			return dyCodeImage;
		},

		getUserOperateId({ userOperateId }) {
			return userOperateId;
		},

		getIsShowNotBind({ isShowNotBind }) {
			return isShowNotBind;
		},

		getIsShowNotBindCode({ isShowNotBindCode }) {
			return isShowNotBindCode;
		}
	},

	mutations: {
		changeSystemInfo(state, params) {
			state.systemInfo = params;
		},

		changeUserInfo(state, params) {
			const { token, ...otherParams } = params;
			state.userInfo = otherParams;

			setLocal(srorageKey.userInfo, otherParams);
			token && this.commit('changeToken', token);
		},

		changeToken(state, params) {
			state.token = params;

			setLocal(srorageKey.AuthorizedToken, params);
		},

		changeDyCodeImage(state, params) {
			state.dyCodeImage = params;
		},

		changeUserOperateId(state, params) {
			state.userOperateId = params;
		},

		changeShowNotBindCode(state, params) {
			console.log(state)
			state.isShowNotBindCode = params;
		},

		changeShowNotBind(state, params) {
			state.isShowNotBind = params;
		}
	}
};
